using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace Cartoon
{  
    partial class EpisodeControl : UserControl
    {
        public EpisodeControl()
        {
            InitializeComponent();
        }

        private void EpisodeControl_Load(object sender, EventArgs e)
        {
            m_CheckBox.Text = m_Episode.Name;            
            this.m_CheckBox.CheckedChanged += new System.EventHandler(this.CheckBox_CheckedChanged);
            Activate();
        }

        private void CheckBox_CheckedChanged(object sender, EventArgs e)
        {
            m_Episode.Checked = !m_Episode.Checked;
        }

        private void DownBtn_Click(object sender, EventArgs e)
        {
            if (Download != null)
                Download(this, new EpisodeEventArgs(m_Episode));           
        }

        private void m_FavoriteBtn_Click(object sender, EventArgs e)
        {
            m_Episode.Favorited = !m_Episode.Favorited;
            if (Favorited != null)
                Favorited(this, new EpisodeEventArgs(m_Episode));
            Activate();
        }

        public bool Checked
        {
            get { return m_Episode.Checked; }
            set { m_CheckBox.Checked = value;}
        }

        public void Activate()
        {
            if (m_Episode.Favorited)
                this.m_FavoriteBtn.Image = global::Cartoon.Properties.Resources.ImageFavorite;
            else
                this.m_FavoriteBtn.Image = global::Cartoon.Properties.Resources.ImageFavorite2;
        }

        public Episode Episode
        {
            get { return m_Episode; }
            set { m_Episode = value; }
        }
        
        public event EventHandler<EpisodeEventArgs> Download = null;
        public event EventHandler<EpisodeEventArgs> Favorited = null;     
        Episode m_Episode;        
    }

    public class EpisodeEventArgs : EventArgs
    {
        public EpisodeEventArgs(Episode episode)
        {
            this.Episode = episode;
        }
        public Episode Episode;
    }
}
